package personresources.manager.component;

import java.io.IOException;
import java.sql.Date;

import javax.el.MethodExpression;
import javax.el.ValueExpression;
import javax.faces.component.UICommand;
import javax.faces.component.UIInput;
import javax.faces.component.html.HtmlCommandLink;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;

/**
 * calendar component
 * @author Duy Chuong
 *
 */
public class UICalendar  extends UICommand{
	private static final String COMPONENY_TYPE = "UICalendar";
	private Date date;
	private String onSelect;
	private String value;
	private String test;
	private MethodExpression method;
	public MethodExpression getMethod() {
		return method;
	}
	public void setMethod(MethodExpression method) {
		this.method = method;
	}
	@Override
	public void restoreState(FacesContext context, Object state) {
		// TODO Auto-generated method stub
		super.restoreState(context, state);
	}
	@Override
	public Object saveState(FacesContext context) {
		// TODO Auto-generated method stub
		return super.saveState(context);
	}
	@Override
	public void encodeBegin(FacesContext context) throws IOException {
		ResponseWriter writer = context.getResponseWriter();
		writer.startElement("div", null);
		Object val =  this.getValue();
		System.out.println("..........." + value);
		ValueExpression ve = getValueExpression("value");
		
		HtmlCommandLink link = new HtmlCommandLink();
		link.setValue(val);
		link.setActionExpression(getActionExpression());
		this.getChildren().add(link);
		if (ve != null) {
			value = ve.getValue(context.getELContext()).toString();
			writer.writeText(value, null);
		}
		
	}
	@Override
	public void encodeEnd(FacesContext context) throws IOException {
		ResponseWriter writer = context.getResponseWriter();
		writer.endElement("div");
	}
	public void setTest(String test) {
		this.test = test;
	}
	public String getTest() {
		return test;
	}
	public void setOnSelect(String onSelect) {
		this.onSelect = onSelect;
	}
	public String getOnSelect() {
		if (onSelect == null) {
			MethodExpression mE = getActionExpression();
			if (mE != null) {
				onSelect = mE.getExpressionString();
			}
		}
		return onSelect;
	}
	
}
